<?php
require './include/global.php';
require './include/validate.php';
require './include/all_left.php';

require_once './include/advisory_db.php';

$smarty->compile_check = true;
$smarty->display('header.tpl');

$job_id = $_GET[id];

if($_GET[action]=='del'){
	  switch ($_GET[type]){
           case submitted:
			if(!empty($_POST[del])){
				foreach($_POST[del] as $value){
					$str[] = "`re_id` = '".$value."' ";
				}
				$where = @implode(' OR ',$str);

				$sql = "DELETE FROM pa_contact WHERE ($where)";
				$DB->query($sql);
			}
			   echo "<meta http-equiv=\"refresh\" content=\"0;URL=contactlist.php?id=$job_id\">";
			   exit;
		   case received:
				if(!empty($_POST[del])){
					foreach($_POST[del] as $value){
						$str[] = "`re_id` = '".$value."' ";
					}
					$where = @implode(' OR ',$str);
					$sql = "DELETE FROM pa_contact WHERE ($where)";
					$DB->query($sql);
				}
				echo "<meta http-equiv=\"refresh\" content=\"0;URL=contactlist.php?id=$job_id\">";
			   exit;
	  }
}
if($_GET[action] == 'updatestats'){
	$reid = $_GET[reid] + 0;
	$stats = $_GET[stats] + 0;
	$sql = " UPDATE pa_contact SET re_isapproved = '".$stats."' WHERE re_id = '".$reid."'";
	$DB->query($sql);
	echo "<meta http-equiv=\"refresh\" content=\"0;URL=contactlist.php?id=$job_id\">";
	exit;
}


//check type
$sql      =   "SELECT * FROM pa_job WHERE jo_id = '".$job_id."' AND jo_uid = '".$_SESSION[uid]."' AND jo_utype ='".$_SESSION[usertype]."'";
$rs       =   $DB->fetch_one_array($sql);
$type     =  (empty($rs))?"Submitted":"Received";
$owner    =  (empty($rs))?" AND a.re_uid = '".$_SESSION[uid]."'":" AND b.jo_uid = '".$_SESSION[uid]."'";

$nav = new buildNav;
$nav->limit = "25";

if($_GET[tpp] == "posted"){
	$sql = "SELECT COUNT(*) AS count FROM pa_contact as a ,pa_job as b  WHERE  b.jo_id = a.re_aliasid AND a.re_aliasid = '".$job_id."' $owner";
}else{
	$sql = "SELECT COUNT(*) AS count FROM pa_contact as a ,pa_job as b  WHERE  b.jo_id = a.re_aliasid AND a.re_aliasid = '".$job_id."' $owner";
}

$total = $DB->fetch_one_array($sql);

$nav->total_result = $total[count];

$by    = "re_regtime"; 
$order = "DESC" ;
if($_GET[tp]==1){
	$_GET[order1]==''&&$order1=1;$_GET[order2]==''&&$order2=1;$_GET[order3]==''&&$order3=1;$_GET[order4]==''&&$order4=1;
	$_GET[order5]==''&&$order5=1;$_GET[order6]==''&&$order6=1;$_GET[order7]==''&&$order7=1;$_GET[order8]==''&&$order8=1;$_GET[order9]==''&&$order9=1;
	switch($_GET[swh]){
	   case 1:
		   $by = "re_regtime";
		   if($_GET[order1]==1){$order_arr[1]=2; $order=" DESC ";$image_arr[1] = "<img src=\"images/dot1.gif\" align=\"absmiddle\">";}else{$order_arr[1]=1;$order=" ASC ";$image_arr[1] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 2:
		   $by = "re_fname";
		   if($_GET[order2]==1){$order_arr[2]=2; $order=" DESC ";$image_arr[2] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[2]=1;$order=" ASC ";$image_arr[2] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 3:
			$by = "re_lostate";
		   if($_GET[order3]==1){$order_arr[3]=2; $order=" DESC ";$image_arr[3] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[3]=1;$order=" ASC ";$image_arr[3] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 4:
		   $by = "jo_myrwe";
		   if($_GET[order4]==1){$order_arr[4]=2; $order=" DESC ";$image_arr[4] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[4]=1;$order=" ASC ";$image_arr[4] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
		case 5:
		   $by = "app_submittime";
		   if($_GET[order5]==1){$order_arr[5]=2; $order=" DESC ";$image_arr[5] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[5]=1;$order=" ASC ";$image_arr[5] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 6:
		   $by = "re_desiredpay";
		   if($_GET[order6]==1){$order_arr[6]=2; $order=" DESC ";$image_arr[6] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[6]=1;$order=" ASC ";$image_arr[6] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	  case 7:
		   $by = "re_schoolattend";
		   if($_GET[order7]==1){$order_arr[7]=2; $order=" DESC ";$image_arr[7] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[7]=1;$order=" ASC ";$image_arr[7] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	  case 8:
		   $by = "re_currentpay";
		   if($_GET[order8]==1){$order_arr[8]=2; $order=" DESC ";$image_arr[8] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[8]=1;$order=" ASC ";$image_arr[8] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	  case 9:
		   $by = "rc_uname";
		   if($_GET[order9]==1){$order_arr[9]=2; $order=" DESC ";$image_arr[9] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[9]=1;$order=" ASC ";$image_arr[9] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	  case 10:
		   $by = "jo_status";
		   if($_GET[order10]==1){$order_arr[10]=2; $order=" DESC ";$image_arr[10] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[10]=1;$order=" ASC ";$image_arr[10] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	  case 11:
		   $by = "re_yearexp";
		   if($_GET[order11]==1){$order_arr[11]=2; $order=" DESC ";$image_arr[11] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[11]=1;$order=" ASC ";$image_arr[11] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	  case 12:
		   $by = "re_edulevel";
		   if($_GET[order12]==1){$order_arr[12]=2; $order=" DESC ";$image_arr[12] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[12]=1;$order=" ASC ";$image_arr[12] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	  case 13:
		   $by = "re_desiredpay";
		   if($_GET[order13]==1){$order_arr[13]=2; $order=" DESC ";$image_arr[13] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[13]=1;$order=" ASC ";$image_arr[13] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	}
		$smarty->assign("order_arr",$order_arr);
		$smarty->assign("image_arr",$image_arr);

}

$sql = "SELECT * FROM pa_contact as a ,pa_job as b  WHERE  b.jo_id = a.re_aliasid AND a.re_aliasid = '".$job_id."' $owner";

$nav->execute($sql." ORDER BY  $by $order");

$page = $nav->pagenav();


$i=0;
while($list2 = $DB->fetch_array($nav->sql_result)){
		
	   $datajob[$i]                  = $list2;
	   $datajob[$i][jo_id]           = $job_id;
	   $datajob[$i][app_regtime]     = @date("m/d/Y h:i:s A",$list2[re_regtime]);
	   $datajob[$i][re_desiredpay]   = "$".number_format($datajob[$i][re_desiredpay]);
	   $datajob[$i][name]            = $list2[re_fname]." ".$list2[re_lname];
	   $datajob[$i][location]        = $state[$list2[re_lostate]].",".$country[$list2[re_locountry]];
	   $datajob[$i][re_yearexp]      = $yearexp2[$list2[re_yearexp]];
	   $datajob[$i][rc_uname]        = $list2[rc_uname];
	   $datajob[$i][re_jobsearchstatus]       = $jobSearchStatus[$list2[re_jobsearchstatus]];

	   $datajob[$i][re_subject]		 = ($list2['re_subject'] != '')?$list2['re_subject']:"N/A";
	   $datajob[$i][jo_status]       = $jobfillstatus[$list2[jo_status]];
	   $datajob[$i][jo_myrwe]      = $yearexp2[$list2[jo_myrwe]];
	   $datajob[$i][re_edulevel]     = $education[$list2[re_edulevel]];
	   $datajob[$i][re_currentpay]	 = number_format($list2[re_currentpay]);
	   $datajob[$i][re_desiredpay]   = number_format($list2[re_desiredpay]);
	   $datajob[$i][jo_vdate]        = ($list2[jo_vdate] == "NA" || $list2[jo_vdate] == "")? "N/A" :@date("m/d/Y",strtotime($list2[jo_vdate]));
	   if($list2['re_uid']>0){
			$sql = "SELECT rc_copname FROM pa_recuiter WHERE rc_id = '".$list2['jo_uid']."'";
			$recInfo = $DB->fetch_one_array($sql);
			$datajob[$i]['rc_copname']  = $recInfo['rc_copname'];
	   }
	   $i++;
}
//print_r($datajob[0]);
$smarty->assign("jobdetail",$datajob[0]);
$smarty->assign("tpp",$_GET[tpp]);

$smarty->assign("contactlist",$datajob);

$smarty->assign("page",$page);
if($err!=''){
$smarty->assign("err",$err);
}
$smarty->assign("job_id",$job_id);
$smarty->assign("appnum", $total[count]);
$smarty->display('allleft.tpl');

//select
if($type == "Received"){
$smarty->display('contactlist_received.tpl');
}else{
$smarty->display('contactlist_submitted.tpl');
}

$smarty->display('footer.tpl');
?>